package com.hssy.wululuaplan.controller;


import com.hssy.wululuaplan.common.Result;
import com.hssy.wululuaplan.form.CourseScheduleForm;
import com.hssy.wululuaplan.service.CourseScheduleService;
import com.hssy.wululuaplan.vo.ClassRecordVo;
import com.hssy.wululuaplan.vo.CourseScheduleVo;
import com.hssy.wululuaplan.vo.CourseScheduleVo2;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  课程计划 前端控制器
 * </p>
 *
 * @author Mr.Hongtao
 * @since 2024-02-28
 */
@Api(tags = "课程计划V2")
@RestController
@RequestMapping("/wululuaplan/course-schedule/v2")
public class CourseScheduleV2Controller {

    @Resource(name = "courseSchedule2")
    private CourseScheduleService courseScheduleService;

    @ApiOperation("查询全部计划")
    @GetMapping("/findAll")
    public Result<List<CourseScheduleVo2>> findAll(@RequestParam(value = "status", required = false) Integer status) {
        List<CourseScheduleVo2> list = courseScheduleService.getAll(status);
        return Result.success(list);
    }



    @ApiOperation("新增课程计划")
    @PostMapping("/create")
    public Result<String> create(@RequestBody CourseScheduleForm form) {
        courseScheduleService.create(form);
        return Result.success();
    }

    @ApiOperation("修改课程计划")
    @PostMapping("/edit")
    public Result<String> edit(@RequestBody CourseScheduleForm form) {
        courseScheduleService.edit(form);
        return Result.success();
    }

    @ApiOperation("删除课程计划")
    @PostMapping("/delete")
    public Result<String> delete(Integer id) {
        int code = courseScheduleService.delete(id);
        if (code == -200) {
            return Result.error(-200,"已有签到记录，不可以修改该课程计划");
        }else {
            return Result.success();
        }
    }

}

